package com.ww.springboot.boot.configuration;//package com.zhkj.starter.config;
//
//import cn.hutool.core.util.RandomUtil;
//import com.baomidou.mybatisplus.core.MybatisConfiguration;
//import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
//import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
//import com.zhkj.starter.redis.TmsRedisUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.springframework.beans.factory.InitializingBean;
//import org.springframework.context.annotation.Configuration;
//
//import javax.annotation.Resource;
//
///**
// 雪花算法 id生成策略调整
// */
//@Configuration
//@Slf4j
//public class TmsWorkerIdAutoConfiguration implements InitializingBean {
//
//
//	private final Long MAX_ID = 31L;
//
//	private final Long MIN_ID = 0L;
//
//	private final String KEY_SUFFIX = ":workerId";
//
//	@Resource
//	SqlSessionFactory sqlSessionFactory;
//
//
//	@Override
//	public void afterPropertiesSet() throws Exception {
//		String applicationName = System.getProperties().getProperty("spring.application.name");
//		String key = applicationName + KEY_SUFFIX;
//		Long workerId = TmsRedisUtil.incrBy(key, 1);
//		workerId = workerId % 32;
//		long dataCenterId = RandomUtil.randomLong(0, 31);
//		log.info("当前节点workerId:{},dataCenterId:{}", workerId, dataCenterId);
//		MybatisConfiguration configuration = (MybatisConfiguration) this.sqlSessionFactory.getConfiguration();
//		IdentifierGenerator identifierGenerator = new DefaultIdentifierGenerator(workerId, dataCenterId);
//		configuration.getGlobalConfig().setIdentifierGenerator(identifierGenerator);
//	}
//}
